﻿@model IEnumerable<ESupervision.Models.Student>

@{
    ViewBag.Title = "Allocate Student";
}

<h2>Alocate Student</h2>

@using (Html.BeginForm("Allocate", "Allocating"))
    {
    @Html.AntiForgeryToken()
<p>
    <button type="submit" name="command" value="Allocate" class="btn btn-link">Allocate</button>
</p>
    if  (ViewBag.Message != null)
    { 
    <div class="row">
        <p><span class="well"> @ViewBag.Message</span></p>
    </div>
    }
    <div class="row">
        <table class="table">
            <tr>
                <th><input type="checkbox" id="selectAll" name="selectAll" /></th>
                <th>
                    @Html.DisplayNameFor(model => model.UserName)
                </th>

                <th>
                    @Html.DisplayNameFor(model => model.FullName)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Email)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.EnrollmentDate)
                </th>
                <th>
                    Authorised
                </th>
                <th>
                    Supervisor
                </th>
                <th>
                    Second Marker
                </th>
            </tr>

            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        <input type="checkbox" name="selectedStudents" value="@item.Id" />
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.UserName)
                    </td>

                    <td>
                        @Html.DisplayFor(modelItem => item.FullName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Email)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.EnrollmentDate)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.AuthorisedStaff.FullName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Supervisor.FullName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.SecondMarker.FullName)
                    </td>

                </tr>
            }

        </table>
    </div>
    }
@section scripts {
    <script>
        $('#selectAll').change(function () {
            if ($(this).prop('checked')) {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', true);
                });
            } else {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', false);
                });
            }
        });
    </script>
}